2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_HYPERLINKBUTTONHANDLER_JUCEHEADER__
27 #define __JUCER_HYPERLINKBUTTONHANDLER_JUCEHEADER__
29 #include "jucer_ButtonHandler.h"
32 //==============================================================================
35 class HyperlinkButtonHandler
: public ButtonHandler
38 //==============================================================================
39 HyperlinkButtonHandler()
40 : ButtonHandler ("Hyperlink Button", "HyperlinkButton", typeid (HyperlinkButton
), 150, 24)
42 registerColour (HyperlinkButton::textColourId
, "text", "textCol");
45 //==============================================================================
46 Component
* createNewComponent (JucerDocument
*)
48 HyperlinkButton
* hb
= new HyperlinkButton ("new hyperlink", URL ("http://www.rawmaterialsoftware.com/juce"));
50 setNeedsButtonListener (hb
, false);
54 void getEditableProperties (Component
* component
, JucerDocument
& document
, Array
<PropertyComponent
*>& properties
)
56 HyperlinkButton
* const hb
= (HyperlinkButton
*) component
;
58 ButtonHandler::getEditableProperties (component
, document
, properties
);
60 properties
.add (new HyperlinkURLProperty (hb
, document
));
62 addColourProperties (component
, document
, properties
);
65 XmlElement
* createXmlFor (Component
* comp
, const ComponentLayout
* layout
)
67 HyperlinkButton
* const hb
= (HyperlinkButton
*) comp
;
69 XmlElement
* const e
= ButtonHandler::createXmlFor (comp
, layout
);
71 e
->setAttribute ("url", hb
->getURL().toString (false));
76 bool restoreFromXml (const XmlElement
& xml
, Component
* comp
, const ComponentLayout
* layout
)
78 HyperlinkButton
* const hb
= (HyperlinkButton
*) comp
;
80 if (! ButtonHandler::restoreFromXml (xml
, comp
, layout
))
83 hb
->setURL (URL (xml
.getStringAttribute ("url", hb
->getURL().toString (false))));
88 const String
getCreationParameters (Component
* comp
)
90 HyperlinkButton
* const hb
= dynamic_cast <HyperlinkButton
*> (comp
);
92 return quotedString (hb
->getButtonText())
94 + quotedString (hb
->getURL().toString (false))
98 void fillInCreationCode (GeneratedCode
& code
, Component
* component
, const String
& memberVariableName
)
100 ButtonHandler::fillInCreationCode (code
, component
, memberVariableName
);
102 code
.constructorCode
<< getColourIntialisationCode (component
, memberVariableName
)
107 //==============================================================================
108 class HyperlinkURLProperty
: public ComponentTextProperty
<HyperlinkButton
>
111 HyperlinkURLProperty (HyperlinkButton
* component_
, JucerDocument
& document_
)
112 : ComponentTextProperty
<HyperlinkButton
> ("URL", 512, false, component_
, document_
)
115 //==============================================================================
116 void setText (const String
& newText
)
118 document
.perform (new HyperlinkURLChangeAction (component
, *document
.getComponentLayout(), URL (newText
)),
119 "Change hyperlink URL");
122 const String
getText() const
124 return component
->getURL().toString (false);
128 class HyperlinkURLChangeAction
: public ComponentUndoableAction
<HyperlinkButton
>
131 HyperlinkURLChangeAction (HyperlinkButton
* const comp
, ComponentLayout
& layout
, const URL
& newState_
)
132 : ComponentUndoableAction
<HyperlinkButton
> (comp
, layout
),
135 oldState
= comp
->getURL();
141 getComponent()->setURL (newState
);
149 getComponent()->setURL (oldState
);
154 URL newState
, oldState
;
161 #endif // __JUCER_HYPERLINKBUTTONHANDLER_JUCEHEADER__